package com.dhcc.bpm.modules.safe.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dhcc.bpm.common.text.Convert;
import com.dhcc.bpm.modules.safe.entity.AppControl;
import com.dhcc.bpm.modules.safe.mapper.AppControlMapper;
import com.dhcc.bpm.modules.safe.service.IAppControlService;
import com.dhcc.bpm.modules.safe.vo.AppControlVO;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName AppControlServiceImpl
 * @Description API访问控制渠道关联表 服务实现类
 * @Author daina
 * @Date 2020/2/21 14:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 */
@Service("opc_app_control")
public class AppControlServiceImpl extends ServiceImpl<AppControlMapper, AppControl> implements IAppControlService {

	@Autowired
	private AppControlMapper appControlMapper;

	@Override
	public IPage<AppControlVO> selectAppControlPage(IPage<AppControlVO> page, AppControlVO appControl) {
		return page.setRecords(baseMapper.selectAppControlPage(page, appControl));
	}

	@Override
	public int deleteApps(Long opcControlId, String ids) {
		return appControlMapper.deleteApps(opcControlId, Convert.toLongArray(ids));
	}

	@Override
	public Boolean batchControllerApp(Long opcControlId, String ids) {
		List<Long> appIds = Func.toLongList(ids);
		ArrayList<AppControl> list = new ArrayList<>();
		appIds.forEach(appId->{
			AppControl ma = new AppControl();
			ma.setOpcAppId(appId);
			ma.setOpcControlId(opcControlId);
			list.add(ma);
		});
		return saveBatch(list);

	}
}
